package com.intelligencesoft.pss.service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.intelligencesoft.pss.dao.SysMenuDao;
import com.intelligencesoft.pss.entity.base.SysMenu;

@Service
public class SysMenuService {
	
	private  Map<String, SysMenu> menuMap = new ConcurrentHashMap<String,SysMenu>();
	
	@Autowired
	private SysMenuDao sysMenuDao;
	
	public List<SysMenu> loadAllMenus(){
		return sysMenuDao.getHibernateTemplate().loadAll(SysMenu.class);
	}
	
	public List<SysMenu> getSysMenusByParentId(String parentId){
		return sysMenuDao.getSysMenusByParentId(parentId);
	}
	
	public List<SysMenu> getMenus(){
		List<SysMenu> firstLevelMenu = sysMenuDao.getSysMenusByParentId(null);
		for (SysMenu sysMenu : firstLevelMenu) {
			String menuId = sysMenu.getId();
			List<SysMenu> menus = sysMenuDao.getSysMenusByParentId(menuId);
			sysMenu.setMenus(menus);
		}
		
		return firstLevelMenu;
	}
}
